<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /**
     * 存在的问题：
     * 1.使用单例的时候，实际与 Person 构造函数无关了
     */
    let instance
    const Person = function (name, age, gender) {
      this.name = name
      this.age = age
      this.gender = gender
    }
    const SingleTon = function (name, age, gender) {
      if (!instance) instance = new Person(name, age, gender)
      return instance
    }
    let singleton1 = SingleTon('henry', 18, 'male')
    let singleton2 = SingleTon('elsiy', 20, 'female')
    console.log(singleton1) //=> {name: "henry", age: 18, gender: "male"}
    console.log(singleton2) //=>  {name: "henry", age: 18, gender: "male"}
    console.log(singleton1 === singleton2) //=> true

  </script>
</body>

</html>